<?php
if (isset($_GET["create_rule"])) {
	$pid = $_GET["create_rule"];
	DataBase::insert("exam_eligibility_rule",array("program_id"=>$pid,"selection_campaign_id"=>$_SESSION["campaign_id"],"type"=>"minimum","mark"=>0));
} else if (isset($_GET["remove_rule"])) {
	$rid = $_GET["remove_rule"];
	DataBase::delete("exam_eligibility_rule",array("exam_eligibility_rule_id"=>$rid));
} else if (isset($_GET["add_subject"])) {
	$sid = $_GET["add_subject"];
	$rid = $_GET["rule"];
	DataBase::insert("exam_eligibility_rule_subjects",array("exam_eligibility_rule_id"=>$rid,"subject_id"=>$sid));
        header("Location:define_rules.php")or die(mysql_error());exit();
} else if (isset($_GET["remove_subject"])) {
	$sid = $_GET["remove_subject"];
	$rid = $_GET["rule"];
	DataBase::delete("exam_eligibility_rule_subjects",array("exam_eligibility_rule_id"=>$rid,"subject_id"=>$sid));
} else if (isset($_GET["change_rule_type"])) {
	$type = $_GET["change_rule_type"];
	$rid = $_GET["rule"];
	DataBase::update("exam_eligibility_rule",array("exam_eligibility_rule_id"=>$rid),array("type"=>$type));
} else if (isset($_GET["apply_rule_to_high_school"])) {
	$id = $_GET["apply_rule_to_high_school"];
	if ($id == "NULL") $id = null;
	$rid = $_GET["rule"];
	DataBase::update("exam_eligibility_rule",array("exam_eligibility_rule_id"=>$rid),array("apply_to_high_school_id"=>$id));
} else if (isset($_GET["apply_rule_to_ngo"])) {
	$id = $_GET["apply_rule_to_ngo"];
	if ($id == "NULL") $id = null;
	$rid = $_GET["rule"];
	DataBase::update("exam_eligibility_rule",array("exam_eligibility_rule_id"=>$rid),array("apply_to_ngo_id"=>$id));
} else if (isset($_GET["mark"])) {
	$mark = $_GET["mark"];
	if (!is_numeric($mark)) {
		echo "<span style='color:red'>Invalid mark '".$mark."': must be a valid numeric value</span><br/>";
	} else {
		$rid = $_GET["rule"];
		DataBase::update("exam_eligibility_rule",array("exam_eligibility_rule_id"=>$rid),array("mark"=>$mark));
	}
}
?>
